<template>
    <div>
      <!-- <Loading v-show="LOADING"></Loading> -->
      <nav-com
        title="商品详情"
        :showView='showView'
        @back="backHandler()"
      ></nav-com>
      <van-pull-refresh
        v-model='isLoading'
        @refresh='onRefresh'
      >

        <div class="d_top">
          <van-swipe :autoplay="3000">
            <van-swipe-item
              v-for="(image, index) in list"
              :key="index"
            >
              <img
                v-lazy="image"
                style="height:220px"
              />
            </van-swipe-item>
          </van-swipe>
        </div>
        <div class="d_price">
          <div class="flex-between">
            <div class="prce_sale"><span style="color: #FA2C1E;">免费领取</span><span class="origin_price">原价￥{{details.price}}</span></div>
            <div class="d_pr_p">已售{{details.sales}}</div>
          </div>
          <p>{{details.title}}</p>
        </div>

        <div style=" background:#F4F4F4;">
          <div class="list-item-top">
          <div class="left">
            <div class="author-img">
              <img :src="shopDetail.avatar" />
            </div>
            <div class="shop-info">
              <div class="name">{{ shopDetail.shopname }}</div>
              <div class="info">
                <img src="@/assets/shop/star.png" />
                {{ shopDetail.description }}
              </div>
            </div>
          </div>
          <div class="right" @click="toshopdetail(shopDetail)">进店逛逛</div>
        </div>
        </div>
        <div class="details_title">
          <i></i>
          <span>商品详情</span>
        </div>
        <div class="d_details">
          <div class="card" v-if="details.is_dx==1&&detailImages.length>0"><img v-lazy="image"  class="img" v-for="(image, index) in detailImages" :key="index"/></div>
          <div class="card" v-else v-html="details.content"></div>
        </div>

        <div class="d_height"></div>
      </van-pull-refresh>
      <div class="d_bottom">
        <div class="d_display">
          <div
            @click="receive"
            class="d_btn"
          >立即领取</div>
        </div>
      </div>
    </div>
  </template>
  <script>
  import navCom from "@/component/nav";
  import Loading from "@/component/loading";
  import {
    friendgoodsdetail,
    yiPayTip,
    shopdetail,
    friendviewNum,
    waitReceive
  } from "@/api/api";
  import { Toast } from 'vant';
  export default {
    name: "odersDetails",
    components: {
      navCom,
      Loading,
    },
    data() {
      return {
        detailsId: "",
        showView: true,
        isLoading: false,
        list: [],
        details: {},
        LOADING: false,
        shopDetail:{},
        detailImages:[],
        uid:weixin.getUserId()||localStorage.getItem('user_id')
      };
    },
    created() {},
    mounted() {
      this.getviewNum()
      console.log("detailsId",this.$route.query)
      this.detailsId = this.$route.query.goods_id
      this.initDatails();
      // this.isTip()
    },
    methods: {
      getviewNum() {
        friendviewNum({
          qr_id:this.$route.query.qrcode_id,
        }).then((res) => {
          if (res.data.code == 1) {}
        });
      },
      isTip() {
        yiPayTip().then((res) => {
          if (res.data.data["status"] == "true") {
            this.$dialog
              .alert({
                title: "支付提示",
                message: "亲！您有未完成预付券支付的订单，请您及时支付，完成订单",
              })
              .then(() => {});
          }
        });
      },
      //返回
      backHandler() {
        if (weixin.isAndroid()&&window.JS_TROOPS) {
          window.JS_TROOPS.goBack();
        } else {
          this.$router.go(-1);
        }
      },
      onRefresh() {
        this.isLoading = false;
      },
      //初始化
      initDatails() {
        this.LOADING = true;
        // this.detailsId = location.href.substring(
        //  location.href.indexOf("details/") + 18
        // );
        friendgoodsdetail({ id: this.detailsId }).then((res) => {
            this.LOADING = false;
            this.details = res.data.data;
            this.list = res.data.data.images? res.data.data.images.split(','):'';
            this.one_day = res.data.data.one_day||'0';
            this.detailImages = this.details.content? this.details.content.split(','):'';
            this.getshopdetail()
          });

      },
      getshopdetail(){
        shopdetail({ id: this.details.shop_id }).then((res) => {
          if (res.data.code == 1) {
            if (res.data.data) {
              this.shopDetail = res.data.data;
            }
          }
        });
      },
      toshopdetail() {
        this.$router.push({
          name: "allshopgoods",
          params: { id:this.details.shop_id },
        });
      },
      //购买
      receive(){
        if(this.uid){
          waitReceive({
            shareUid:this.$route.query.uid,
            goods_id:this.$route.query.goods_id,
            uid:this.uid,
            qrcode_id:this.$route.query.qrcode_id,
          }).then((res) => {
            if (res.data.code == 1) {
              if((weixin.isAndroid()&&window.JS_TROOPS)||localStorage.getItem("token")){
                // this.$router.push({
                //     name:'orderDetail5g',
                //     params:{id:this.orderObj.id}
                // });
                this.$router.push({
                  name: "freePay",
                  params: { id: this.detailsId, one_day: 0,r_id:res.data.data,},
                });
              }
            }
          });
        }else{
           if(this.$is_weixn){
            this.$router.push('/register_weixin')
          }else{
            this.$router.push('/login')
          }
        }
      }
    },
  };
  </script>
  <style scoped>
  .card,
  img,
  div,
  p {
    margin: 0;
    padding: 0;
    border: none;
  }
  .card >>> img {
    display: block;
    width: 100%;
    height: auto;
    float: left;
  }
  .d_top img {
    width: 100%;
  }
  .d_price {
    padding:0 4vw 4vw;
    margin-top: 2.6vw;
  }
  .d_price .flex-between{
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .d_price .flex-between .prce_sale .origin_price{
    text-decoration:line-through;
    font-size:13px;
    color:#444444;
    margin-left: 6px;
  }
  .d_price span {
    font-size: 5.6vw;
    color: #cb041c;
  }
  .details_title {
    font-size: 4.2vw;
    width: 100%;
    margin-left: 4vw;
    margin-top: 4vw;
    text-align: left;
  }
  .details_title i {
    width: 1.066vw;
    height: 4vw;
    background: #f7541c;
    margin-top: 1vw;
    margin-right: 1.3vw;
    display: block;
    float: left;
  }
  .details_title span {
    float: left;
    display: block;
  }
  .d_details{
    clear: both;
    padding: 10px;
  }
  .d_pr_p {
    font-size: 2.9vw;
    color: #999;
    margin-top: 2.6vw;
  }
  .list-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 10px;
}
.list-item-top .right {
  width: 80px;
  height: 26px;
  font-family: PingFangSC-Regular, PingFang SC;
  border-radius: 15px;
  font-size: 13px;
  background: linear-gradient(90deg, #FF4050 0%, #FA2C1E 100%);
  font-weight: 400;
  color: #ffffff;
  line-height: 26px;
  text-align: center;
}
.list-item-top .left {
  display: flex;
  align-items: center;
}
.list-item-top .left .author-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin-right: 6px;
}
.author-img img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}
.shop-info .name {
  font-size: 13px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 550;
  color: #222222;
  line-height: 25px;
}
.shop-info .info {
  font-size: 11px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #949391;
  line-height: 16px;
  display: flex;
  align-items: center;
}
.shop-info .info img {
  width: 16px;
  margin-right: 5px;
}
  .details_img img {
    width: 100%;
  }
  .d_height {
    height: 18.66vw;
  }
  .d_bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 18.66vw;
    background: #fff;
    height: 18.66vw;
  }
  .d_display {
    margin: 3.3vw;
    width: auto;
  }
  .d_btn {
    width: 94.66vw;
    height: 12vw;
    line-height: 12vw;
    font-size: 4vw;
    background: #d62f34;
    border-radius: 6vw;
    text-align: center;
    color: #fff;
  }
  </style>
